#ifndef TESTVIEW_H
#define TESTVIEW_H
#include "cshape.h"
#include "svglineitem.h"
#include "svgrectangleitem.h"
#include "svgtriangleitem.h"
#include "svgellipseitem.h"
#include "svgbezieritem.h"
#include <QGraphicsView>
#include <QWheelEvent>
# include <QTimer>

const int TIMEOUT = 1;

class SvgView : public QGraphicsView {
    Q_OBJECT
public:
    SvgView(QWidget* parent = nullptr);
    // 指示当前绘制的图形
    WitchGraphic CurrentAction;
    // 定义图形是否被拖拽
    bool isDragOn;
    // 描述绘制线条的属性
    QPen PenForLine;
    // 描述填充图形的属性
    QBrush BrushForShape;
protected:
    void keyPressEvent(QKeyEvent* event) override;
    void wheelEvent(QWheelEvent* event) override;
    void mousePressEvent(QMouseEvent* event) override;
    void mouseMoveEvent(QMouseEvent* event) override;
    void mouseReleaseEvent(QMouseEvent* event) override;
    // 表示图像起点
    QPointF startPoint;
    // 表示图像终点（鼠标按下时，为当前鼠标位置）
    QPointF endPoint;
    // 当前绘制的图像的指针
    CShape *CurrentItem;
    // 定时用于动态刷新
    QTimer *timer;
protected slots:
    void TimeOutSlots() {
        CurrentItem->SetStartandEnd(startPoint, endPoint);
        CurrentItem->GenerateControlPoints();
        viewport()->update();
    }
};

#endif // TESTVIEW_H
